package com.xxxx.seckill.vo;

import lombok.*;
import springfox.documentation.spring.web.json.Json;

/**
 * @author heyanfeng
 * @version 1.0
 * @description:  公共返回对象
 * @date 2022/7/29 15:49
 */
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class RespBean {

    private long code;
    private String message;
    private Json info;

    /**
     * 成功的返回
     * @author yanfeng
     * @date 2023-02-07
     * @return
     */
    public static RespBean success(){
        return new RespBean(RespBeanEnum.SUCCESS.getCode(),RespBeanEnum.SUCCESS.getMessage(), null);
    }

    /**
     * 重写方法，成功且返回参数
     * @author yanfeng
     * @date 2023-02-07
     * @param obj
     * @return
     */
    public static RespBean success(Object obj){
        return new RespBean(RespBeanEnum.SUCCESS.getCode(),RespBeanEnum.SUCCESS.getMessage(), obj);
    }

    /**
     * 失败有多种失败的原因500、400、404等，所以可用枚举做参数来进行错误返回。
     * @author yanfeng
     * @date 2023-02-07
     * @param respBeanEnum
     * @return
     */
    public static RespBean error(RespBeanEnum respBeanEnum){
        return new RespBean(respBeanEnum.getCode() , respBeanEnum.getMessage(), null);
    }

    /**
     * 重写方法，报错且返回参数
     * @author yanfeng
     * @date 2023-02-07
     * @param respBeanEnum
     * @param obj
     * @return
     */
    public static RespBean error(RespBeanEnum respBeanEnum, Object obj){
        return new RespBean(respBeanEnum.getCode() , respBeanEnum.getMessage(),obj);
    }
}
